pub trait YamPlugin {
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn init(&self, config: &Config) -> Result<(), PluginError>;
    fn register_cli(&self, app: Command) -> Command;
    fn execute_command(&self, cmd: &str, args: &[String]) -> Result<(), PluginError>;
}

#[derive(Debug)]
pub struct PluginManager {
    plugins: HashMap<String, Arc<dyn YamPlugin>>,
}

impl PluginManager {
    pub fn load_plugin(&mut self, path: &str) -> Result<(), PluginError> {
        #[cfg(feature = "plugins")]
        {
            let lib = Library::new(path)?;
            let constructor: Symbol<unsafe extern "C" fn() -> *mut dyn YamPlugin> =
                unsafe { lib.get(b"plugin_create") }?;
            let plugin = unsafe { Arc::from_raw(constructor()) };
            self.plugins.insert(plugin.name().to_string(), plugin);
            Ok(())
        }
        #[cfg(not(feature = "plugins"))]
        Err(PluginError::Disabled)
    }
}